package com.zytj.rs.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zytj.rs.dao.IMemberDao;
import com.zytj.rs.dto.MemberDTO;
import com.zytj.rs.model.Member;
import com.zytj.rs.service.IMemberService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "会员列表")
@RestController
@RequestMapping("/men")
public class MemberController {

	@Resource
	private IMemberService memberService;
	@Resource
	private IMemberDao memberDao;
	@ApiOperation(value = "根据条件查",notes = "根据条件查")
	@PostMapping
	public Map findMember(@ModelAttribute MemberDTO dto) {
		return memberService.findAll(dto);
	}
	
	@ApiOperation(value = "查询所有",notes = "查询所有")
	@GetMapping
	public List<Member> findAll() {
		return memberDao.findAll();
	}
	
	@ApiOperation(value = "删除",notes = "删除")
	@DeleteMapping("{id}")
	public String del(int id) {
		memberDao.deleteById(id);
		return "删除成功";
	}
	
	
	@ApiOperation(value = "添加或修改",notes = "添加或修改")
	@PostMapping("/addOrEdit")
	public String addOrEdit(@ModelAttribute Member member) {
		memberDao.save(member);
		return "保存成功";
	}
	
	@ApiOperation(value = "修改会员状态",notes = "修改会员状态为0")
	@PostMapping("{id}")
	public String UpdateStatus(int id) {
		memberDao.UpdateStatus(id);
		return "修改成功";
	}
}
